import React from 'react';
import { useAuth } from '../context/AuthContext';

interface PermissionGuardProps {
  children: React.ReactNode;
  requireAdmin?: boolean;
  requireModerator?: boolean;
  fallback?: React.ReactNode;
}

const PermissionGuard: React.FC<PermissionGuardProps> = ({
  children,
  requireAdmin = false,
  requireModerator = false,
  fallback = null,
}) => {
  const { isAdmin, isModerator } = useAuth();

  // 如果需要管理员权限
  if (requireAdmin && !isAdmin()) {
    return <>{fallback}</>;
  }

  // 如果需要审核员权限
  if (requireModerator && !isModerator()) {
    return <>{fallback}</>;
  }

  return <>{children}</>;
};

export default PermissionGuard; 